from pms.common.views import PostFormula
from user.utils.profile import role_view
from user.utils.role import update_role
from user.models import Role


class API(PostFormula):

    require_permissions = [12]

    def handle(self, req):
        rid = req['id']
        mod = req['mod']
        role = update_role(
            role=Role.objects.get(id=rid),
            view=mod
        )
        return self.success_respond(role_view(role))
